const router = require('koa-router')()
const { exec } = require('../db/index')
// 路由前缀
router.prefix('/api/blog')
/**
 * 路由：
 * 1. /api/blog     get  查询所有的文章
 * 2. /api/blog     post 新增数据
 * 3. /api/blog/:id put  修改数据
 * 4. /api/blog/:id delete 删除数据
 * 
 */

router.get('/', async (ctx, next) => {
  const sql = `select * from blogs;`
  const data = await exec(sql)
  ctx.body = data
})

router.post('/', async (ctx, next) => {
   ctx.body = ctx.request.body;
})
router.put('/:id', async (ctx, next) => {
   ctx.body = '修改数据'
})
router.delete('/:id', async (ctx, next) => {
   ctx.body = '删除数据'
})


module.exports = router;
